package net.ojbk.timeSpace.timeAxis.web.handlers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import net.ojbk.timeSpace.timeAxis.beans.TimeAxis;
import net.ojbk.timeSpace.timeAxis.beans.TimeBlade;
import net.ojbk.timeSpace.timeAxis.service.IAxisService;

@Controller
@RequestMapping("")
public class AxisController {
	
	@Autowired
	@Qualifier("axisService")
	private IAxisService axisService;
	/**
	 * 简介：所有人都可以访问时光轴，所以只需要时光轴id即可
	 * 
	 * @return {‘axisId’, 'axisTitle', 'axisInfo'}
	 */
	@RequestMapping(value = "/getAxisInfo.do", params = {"axisId"})
	@ResponseBody
	public Object doGetAxisInfo(@RequestParam(name="axisId") int axisId){
		TimeAxis timeAxis = axisService.getOneAxis(axisId);
		HashMap<String, String> reMap = new HashMap<>();
		
		// TODO 
		reMap.put("axisId", timeAxis.getAxisId()+"");
		reMap.put("axisTitle", timeAxis.getAxisTitle());
		reMap.put("axisInfo", timeAxis.getAxisInfo());
		return reMap;
	}
	
	
	/**
	 * 简介：所有人都可以访问时光轴，所以只需要时光轴id即可
	 * 要求：返回一个LIST集合，每个集合有一个MAP
	 * 
	 * @return [{‘timeBladeId’, 'timeBladeTitle', 'timeBladeBrief', 'pushDate'},{}]
	 */
	@RequestMapping(value = "/getBladeList.do", params = {"axisId"})
	@ResponseBody
	public Object doGetBladeList(@RequestParam(name="axisId") int axisId){
		HashMap<String,String> bladeMap = new HashMap<>();
		List<HashMap<String,String>> bladeMapList = new ArrayList<HashMap<String,String>>();
		List<TimeBlade> timeBladeList = axisService.getAllBladeByAxisId(axisId);
		for (TimeBlade eachTimeBlade : timeBladeList) {
			bladeMap.put("timeBladeId", eachTimeBlade.getTimeBladeId()+"");
			bladeMap.put("timeBladeTitle", eachTimeBlade.getTimeBladeTitle());
			bladeMap.put("timeBladeBrief", eachTimeBlade.getTimeBladeInfo());
			bladeMap.put("pushDate", eachTimeBlade.getPushDate().toString());
			
			bladeMapList.add(bladeMap);
		}
		return bladeMapList;
	}
	
	// 发布时光叶片
	@RequestMapping(value = "/publishTime.do", params = {"axisId"})
	public ModelAndView doPublishTime(HttpSession session, String title) {
		
		return null;
	}
	
	
	
}
